package CS4310.csueb.visual;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import CS4310.csueb.characters.Hero;

///////////////////////////////// class heroSprite ////////////////////////////////
//like "sprite" but will listen for keyboard input
public class HeroSprite extends Sprite implements KeyListener{

	private static final long serialVersionUID = 2714936100723973701L;
	private Hero heroSheet;

	// ********** constructor ************//
	public HeroSprite(String pfilename, String name, int hp, int attack, int defense, int speed) {
		super(pfilename);
		heroSheet = new Hero (name, hp, attack, defense, speed);
	}
	
	public HeroSprite(String pfilename, String name) {
		super(pfilename);
		heroSheet = new Hero (name);
	}

	// ********** constructor ************//
	public HeroSprite(String pfilename, int px, int py) {
		super(pfilename, px, py);
	}
	
	// ********** keyPressed ***********/
	// updated method to allow for the use of arrow keys
	public void keyPressed(KeyEvent e) {
		char key = e.getKeyChar();
		int numKey = e.getKeyCode();

		// these values will in the future be effected by the character.speed
		if (key == 'a' || numKey == KeyEvent.VK_LEFT) {
			dx = -2;
		}

		if (key == 'd' || numKey == KeyEvent.VK_RIGHT) {
			dx = 2;
		}

		if (key == 'w' || numKey == KeyEvent.VK_UP) {
			dy = -2;
		}

		if (key == 's' || numKey == KeyEvent.VK_DOWN) {
			dy = 2;
		}
	}

	// ********** keyReleased ***********//
	// coordinates changed by 0 if key is released
	// updated method to allow for the use of arrow keys
	public void keyReleased(KeyEvent e) {
		char key = e.getKeyChar();
		int numKey = e.getKeyCode();

		if (key == 'a' || numKey == KeyEvent.VK_LEFT) {
			dx = 0;
		}

		if (key == 'd' || numKey == KeyEvent.VK_RIGHT) {
			dx = 0;
		}

		if (key == 'w' || numKey == KeyEvent.VK_UP) {
			dy = 0;
		}

		if (key == 's' || numKey == KeyEvent.VK_DOWN) {
			dy = 0;
		}
	}

	// *********** keyTyped ************//
	// empty
	public void keyTyped(KeyEvent e) {
	}
	
	public Hero getHeroSheet(){
		return heroSheet;
	}
	
	/*public void actionPerformed(ActionEvent e) {
			keyReleased(e);
			move();
			repaint();
		}
		*/
		
}

